<template>
  <div class="patient-detail-container" v-if="patient">
    <!-- 患者基本信息 -->
    <div class="basic-info-section">
      <div class="patient-avatar">
        <el-avatar :size="80" :style="{ backgroundColor: getAvatarColor(patient.name) }">
          {{ patient.name.charAt(0) }}
        </el-avatar>
      </div>
      <div class="patient-basic-info">
        <h3>{{ patient.name }}</h3>
        <div class="basic-details">
          <div class="detail-item">
            <span class="label">性别：</span>
            <span class="value">{{ patient.gender }}</span>
          </div>
          <div class="detail-item">
            <span class="label">年龄：</span>
            <span class="value">{{ patient.age }}岁</span>
          </div>
          <div class="detail-item">
            <span class="label">床号：</span>
            <span class="value">{{ patient.bedNumber }}</span>
          </div>
          <div class="detail-item">
            <span class="label">入院日期：</span>
            <span class="value">{{ patient.admissionDate }}</span>
          </div>
        </div>
      </div>
      <div class="status-indicators">
        <el-tag :type="getCareLevelType(patient.careLevel)" size="large">
          {{ patient.careLevel }}
        </el-tag>
        <el-tag :type="getStatusType(patient.status)" size="large">
          {{ patient.status }}
        </el-tag>
      </div>
    </div>

    <el-divider />

    <!-- 详细信息标签页 -->
    <el-tabs v-model="activeTab" class="detail-tabs">
      <!-- 医疗信息 -->
      <el-tab-pane label="医疗信息" name="medical">
        <div class="info-grid">
          <div class="info-item">
            <span class="label">科室：</span>
            <span class="value">{{ patient.department }}</span>
          </div>
          <div class="info-item">
            <span class="label">主治医生：</span>
            <span class="value">{{ patient.doctor }}</span>
          </div>
          <div class="info-item">
            <span class="label">诊断：</span>
            <span class="value">{{ patient.diagnosis }}</span>
          </div>
          <div class="info-item">
            <span class="label">过敏史：</span>
            <span class="value">{{ patient.allergies || '无' }}</span>
          </div>
          <div class="info-item full-width">
            <span class="label">病史：</span>
            <span class="value">{{ patient.medicalHistory || '无特殊病史' }}</span>
          </div>
        </div>
      </el-tab-pane>

      <!-- 联系方式 -->
      <el-tab-pane label="联系方式" name="contact">
        <div class="info-grid">
          <div class="info-item">
            <span class="label">患者电话：</span>
            <span class="value">{{ patient.phone }}</span>
          </div>
          <div class="info-item">
            <span class="label">紧急联系人：</span>
            <span class="value">{{ patient.emergencyContact }}</span>
          </div>
          <div class="info-item">
            <span class="label">紧急联系电话：</span>
            <span class="value">{{ patient.emergencyPhone }}</span>
          </div>
          <div class="info-item full-width">
            <span class="label">联系地址：</span>
            <span class="value">{{ patient.address || '未填写' }}</span>
          </div>
        </div>
      </el-tab-pane>

      <!-- 护理信息 -->
      <el-tab-pane label="护理信息" name="nursing">
        <div class="nursing-info">
          <div class="nursing-stats">
            <div class="stat-item">
              <div class="stat-number">12</div>
              <div class="stat-label">今日护理项</div>
            </div>
            <div class="stat-item">
              <div class="stat-number">8</div>
              <div class="stat-label">已完成</div>
            </div>
            <div class="stat-item">
              <div class="stat-number">4</div>
              <div class="stat-label">待完成</div>
            </div>
          </div>

          <div class="nursing-plan">
            <h4>护理计划</h4>
            <ul class="plan-list">
              <li v-for="(item, index) in nursingPlan" :key="index" class="plan-item">
                <el-icon><Check /></el-icon>
                <span>{{ item }}</span>
              </li>
            </ul>
          </div>

          <div class="special-notes">
            <h4>特别注意事项</h4>
            <p>{{ patient.specialNotes || '无特别注意事项' }}</p>
          </div>
        </div>
      </el-tab-pane>

      <!-- 生命体征 -->
      <el-tab-pane label="生命体征" name="vitals">
        <div class="vitals-section">
          <div class="vitals-chart">
            <h4>最近24小时生命体征</h4>
            <div class="chart-placeholder">
              <el-icon><TrendCharts /></el-icon>
              <p>生命体征趋势图表</p>
            </div>
          </div>
          
          <div class="latest-vitals">
            <h4>最新测量数据</h4>
            <div class="vitals-grid">
              <div class="vital-item">
                <div class="vital-label">体温</div>
                <div class="vital-value">36.8°C</div>
                <div class="vital-time">10:30</div>
              </div>
              <div class="vital-item">
                <div class="vital-label">脉搏</div>
                <div class="vital-value">78次/分</div>
                <div class="vital-time">10:30</div>
              </div>
              <div class="vital-item">
                <div class="vital-label">呼吸</div>
                <div class="vital-value">18次/分</div>
                <div class="vital-time">10:30</div>
              </div>
              <div class="vital-item">
                <div class="vital-label">血压</div>
                <div class="vital-value">125/80mmHg</div>
                <div class="vital-time">10:30</div>
              </div>
              <div class="vital-item">
                <div class="vital-label">血氧</div>
                <div class="vital-value">98%</div>
                <div class="vital-time">10:30</div>
              </div>
            </div>
          </div>
        </div>
      </el-tab-pane>
    </el-tabs>

    <!-- 快速操作按钮 -->
    <div class="action-buttons">
      <el-button type="primary" :icon="Edit">编辑信息</el-button>
      <el-button :icon="Document">护理记录</el-button>
      <el-button :icon="Monitor">记录体征</el-button>
      <el-button :icon="ChatDotRound">添加备注</el-button>
    </div>
  </div>
</template>

<script setup>
import { ref } from 'vue'
import {
  Edit,
  Document,
  Monitor,
  ChatDotRound,
  Check,
  TrendCharts
} from "@element-plus/icons-vue";

const props = defineProps({
  patient: {
    type: Object,
    required: true
  }
})

const activeTab = ref('medical')

// 模拟护理计划数据
const nursingPlan = ref([
  '每4小时测量一次生命体征',
  '按时给予口服药物治疗',
  '协助患者进行康复训练',
  '监测伤口愈合情况',
  '提供营养饮食指导'
])

// 获取护理级别标签类型
const getCareLevelType = (level) => {
  const map = {
    '特级护理': 'danger',
    '一级护理': 'warning',
    '二级护理': 'primary',
    '三级护理': 'success'
  }
  return map[level] || 'info'
}

// 获取状态标签类型
const getStatusType = (status) => {
  const map = {
    '危重': 'danger',
    '在院': 'warning',
    '康复中': 'primary',
    '待出院': 'success'
  }
  return map[status] || 'info'
}

// 根据姓名生成头像背景色
const getAvatarColor = (name) => {
  const colors = [
    '#1a75bc', '#f56c6c', '#67c23a', '#e6a23c', 
    '#909399', '#8e44ad', '#16a085', '#e74c3c'
  ]
  const charCode = name.charCodeAt(0)
  return colors[charCode % colors.length]
}
</script>

<style lang="scss" scoped>
.patient-detail-container {
  padding: 0 10px;
}

.basic-info-section {
  display: flex;
  align-items: center;
  gap: 24px;
  margin-bottom: 20px;
}

.patient-avatar {
  flex-shrink: 0;
}

.patient-basic-info {
  flex: 1;
  
  h3 {
    margin: 0 0 12px 0;
    font-size: 24px;
    color: #303133;
  }
}

.basic-details {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px 20px;
}

.detail-item {
  display: flex;
  
  .label {
    color: #606266;
    min-width: 70px;
  }
  
  .value {
    font-weight: 500;
    color: #303133;
  }
}

.status-indicators {
  display: flex;
  flex-direction: column;
  gap: 10px;
  flex-shrink: 0;
}

.detail-tabs {
  margin-bottom: 24px;
}

.info-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 16px;
}

.info-item {
  display: flex;
  
  .label {
    color: #606266;
    min-width: 80px;
  }
  
  .value {
    font-weight: 500;
    color: #303133;
  }
  
  &.full-width {
    grid-column: 1 / -1;
  }
}

.nursing-info {
  .nursing-stats {
    display: flex;
    gap: 20px;
    margin-bottom: 24px;
  }
  
  .stat-item {
    text-align: center;
    padding: 16px;
    background: #f5f7fa;
    border-radius: 8px;
    flex: 1;
  }
  
  .stat-number {
    font-size: 24px;
    font-weight: 600;
    color: #1a75bc;
    margin-bottom: 4px;
  }
  
  .stat-label {
    color: #606266;
    font-size: 14px;
  }
}

.plan-list {
  list-style: none;
  padding: 0;
  margin: 0 0 24px 0;
}

.plan-item {
  display: flex;
  align-items: center;
  padding: 8px 0;
  
  .el-icon {
    color: #67c23a;
    margin-right: 8px;
  }
}

.special-notes {
  padding: 16px;
  background: #fff6f6;
  border-radius: 8px;
  border-left: 4px solid #f56c6c;
  
  h4 {
    margin: 0 0 8px 0;
    color: #f56c6c;
  }
  
  p {
    margin: 0;
    color: #606266;
    line-height: 1.6;
  }
}

.vitals-section {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: 24px;
}

.vitals-chart {
  h4 {
    margin: 0 0 16px 0;
  }
}

.chart-placeholder {
  height: 200px;
  background: #f5f7fa;
  border-radius: 8px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: #909399;
  
  .el-icon {
    font-size: 48px;
    margin-bottom: 8px;
  }
}

.latest-vitals {
  h4 {
    margin: 0 0 16px 0;
  }
}

.vitals-grid {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.vital-item {
  padding: 12px;
  background: #f5f7fa;
  border-radius: 8px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.vital-label {
  color: #606266;
  font-weight: 500;
}

.vital-value {
  font-weight: 600;
  color: #303133;
}

.vital-time {
  color: #909399;
  font-size: 12px;
}

.action-buttons {
  display: flex;
  gap: 12px;
  justify-content: center;
  padding-top: 20px;
  border-top: 1px solid #ebeef5;
}

// 响应式设计
@media (max-width: 768px) {
  .basic-info-section {
    flex-direction: column;
    text-align: center;
    gap: 16px;
  }
  
  .status-indicators {
    flex-direction: row;
    justify-content: center;
  }
  
  .basic-details {
    grid-template-columns: 1fr;
  }
  
  .info-grid {
    grid-template-columns: 1fr;
  }
  
  .nursing-stats {
    flex-direction: column;
  }
  
  .vitals-section {
    grid-template-columns: 1fr;
  }
  
  .action-buttons {
    flex-wrap: wrap;
  }
}
</style>